//
//  XQPositionCompanyDetailTableHeaderView.swift
//  XiaoQiQiaoSwift
//
//  Created by tech-lab on 2016/12/2.
//  Copyright © 2016年 校企桥. All rights reserved.
//

import UIKit

class XQPositionCompanyDetailTableHeaderView: UIView {

    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */
    
    var icon = UIImageView()
    var companyLabel = UILabel()
    var cityLabel = UILabel()
    var sizeLabel = UILabel()
    var typeLabel = UILabel()

    private var homepageButton = UIButton()
    private var positionButton = UIButton()
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        self.backgroundColor = UIColor.white
        InitUI()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    var companyInfoMode:XQPositionDetailPDMode?{
        didSet{
            if ((companyInfoMode?.logo) != nil) {
                let url = URL.init(string: (companyInfoMode?.logo)!)
                icon.kf.setImage(with: url)
            }
            companyLabel.text = companyInfoMode?.company_name
            cityLabel.text = companyInfoMode?.area_id
            typeLabel.text = companyInfoMode?.company_type
            sizeLabel.text = companyInfoMode?.company_size

            
        }
        
    }
    
    
    func InitUI(){
        
        icon = UIImageView.init(frame: CGRect.zero)
        self .addSubview(icon)
        
        companyLabel = UILabel.init(frame: CGRect.zero)
        self .addSubview(companyLabel)
        
        cityLabel = UILabel.init(frame: CGRect.zero)
        cityLabel.font = UIFont.systemFont(ofSize: 14)
        self.addSubview(cityLabel)
        
        typeLabel = UILabel.init(frame: CGRect.zero)
        typeLabel.font = UIFont.systemFont(ofSize: 14)
        self.addSubview(typeLabel)
        
        sizeLabel = UILabel.init(frame: CGRect.zero)
        sizeLabel.font = UIFont.systemFont(ofSize: 14)
        self.addSubview(sizeLabel)
        
        
        icon.snp.makeConstraints { (make) in
            make.left.equalTo(self.snp.left).offset(5)
            make.top.equalTo(self.snp.top).offset(10)
            make.width.equalTo(60)
            make.height.equalTo(60)
        }
        
        companyLabel.snp.makeConstraints { (make) in
            make.left.equalTo(icon.snp.right).offset(5)
            make.top.equalTo(self.snp.top).offset(10)
        }
        
        cityLabel.snp.makeConstraints { (make) in
            make.left.equalTo(icon.snp.right).offset(5)
            make.bottom.equalTo(icon.snp.bottom)
        }
        
        let line1 = UIView.init(frame: CGRect.zero)
        line1.backgroundColor = UIColor.lightGray
        self.addSubview(line1)
        
        line1.snp.makeConstraints { (make) in
            make.left.equalTo(cityLabel.snp.right).offset(2)
            make.width.equalTo(0.5)
            make.height.equalTo(15)
            make.centerY.equalTo(cityLabel.snp.centerY)
        }
        
        
        typeLabel.snp.makeConstraints { (make) in
            make.left.equalTo(line1.snp.right).offset(5)
            make.bottom.equalTo(icon.snp.bottom)
        }
        
        let line2 = UIView.init(frame: CGRect.zero)
        line2.backgroundColor = UIColor.lightGray
        self.addSubview(line2)
        
        line2.snp.makeConstraints { (make) in
            make.left.equalTo(typeLabel.snp.right).offset(2)
            make.width.equalTo(0.5)
            make.height.equalTo(15)
            make.centerY.equalTo(cityLabel.snp.centerY)
        }
        
        sizeLabel.snp.makeConstraints { (make) in
            make.left.equalTo(line2.snp.right).offset(5)
            make.bottom.equalTo(icon.snp.bottom)
        }
        
        homepageButton = UIButton.init(frame: CGRect.zero)
        homepageButton.setTitle("公司主页", for: .normal)
        homepageButton.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        homepageButton.setTitleColor(UIColor.black, for: .normal)
        homepageButton.backgroundColor = UIColor.lightGray
        homepageButton.layer.borderWidth = 1
        homepageButton.layer.borderColor = UIColor.lightGray.cgColor
        self.addSubview(homepageButton)
        homepageButton.tag = 1
        
        positionButton = UIButton.init(frame: CGRect.zero)
        positionButton.setTitle("招聘职位", for: .normal)
        positionButton.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        positionButton.setTitleColor(UIColor.black, for: .normal)
       // positionButton.backgroundColor = UIColor.blue
        positionButton.layer.borderWidth = 1
        positionButton.layer.borderColor = UIColor.lightGray.cgColor
        self.addSubview(positionButton)
        positionButton.tag = 2
        
        homepageButton.snp.makeConstraints { (make) in
            make.left.equalTo(self.snp.left).offset(5)
            make.top.equalTo(icon.snp.bottom).offset(10)
            make.width.equalTo(SCREEN_WIDTH/2-5)
            make.height.equalTo(40)
        }
        positionButton.snp.makeConstraints { (make) in
            make.right.equalTo(self.snp.right).offset(-5)
            make.top.equalTo(icon.snp.bottom).offset(10)
            make.width.equalTo(SCREEN_WIDTH/2-5)
            make.height.equalTo(40)
        }
        
        
        homepageButton.addTarget(self, action: #selector(self.switchAction), for: .touchUpInside)
        positionButton.addTarget(self, action: #selector(self.switchAction), for: .touchUpInside)

    }

    func switchAction(sender:UIButton) {
        if sender.tag == 1 {
                homepageButton.backgroundColor = UIColor.lightGray
                positionButton.backgroundColor = UIColor.white
            NotificationCenter.default.post(name: NSNotification.Name(rawValue: "companyIntro"), object: nil)
        }else{
                homepageButton.backgroundColor = UIColor.white
                positionButton.backgroundColor = UIColor.lightGray
            NotificationCenter.default.post(name: NSNotification.Name(rawValue: "companyRecruit"), object: nil)

        }
        
    }
    
}
